/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 19182
 * Date: 2025-11-01
 * Time: 22:10
 */
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution12{
    public int sumOfUnique(int[] nums) {
        int ret = 0;
        int[] hash = new int[101];
        for(int i = 0; i < nums.length; i++){
            hash[nums[i]]++;
        }
        // 遍历哈希数组的索引（即数字本身），累加出现次数为1的数字
        for(int i = 0; i < 101; i++){
            if(hash[i] == 1){
                ret += i;
            }
        }
        return ret;
    }
}
class Solution11{
    public TreeNode searchBST(TreeNode root, int val) {
        return dfs(root, val);
    }
    public TreeNode dfs(TreeNode root, int val){
        if(root == null){
            return null;
        }
        if(root.val == val){
            return root;
        }
        return val < root.val ? dfs(root.left, val) : dfs(root.right, val);
    }
}
class Solution10 {
    public int count = 0;
    public int ret = 0;
    public int kthSmallest(TreeNode root, int k) {
        count = k;
        dfs(root);
        return ret;
    }
    public void dfs(TreeNode root){
        if(root == null){
            return;
        }
        if(count == 0){
            return;
        }
        dfs(root.left);
        count--;
        if(count == 0){
            ret = root.val;
        }
        if(count == 0){
            return;
        }
        dfs(root.right);
    }
}
class Solution1{
    public int count = 0;
    public int ret = 0;
    public int kthSmallest(TreeNode root, int k) {
        count = k;
        dfs(root);
        return ret;
    }
    public void dfs(TreeNode root){
        if(root == null){
            return;
        }
        if(count == 0){
            return;
        }
        dfs(root.left);
        count--;
        if(count == 0){
            ret = root.val;
        }
        if(count == 0){
            return;
        }
        dfs(root.right);
    }
}
class Solution4{
    public TreeNode pruneTree(TreeNode root) {
        if(root == null){
            return null;
        }
        //这里必须写root.left和root.right才能剪枝，如果是用变量来存储那么不会改变树本身，而是改变局部引用变量的值
        root.left = pruneTree(root.left);
        root.right = pruneTree(root.right);
        if(root.left == null && root.right == null && root.val == 0){
            return null;
        }
        return root;
    }
}
class Solution3 {
    public int sumNumbers(TreeNode root) {
        return dfs(root, 0);
    }
    public int dfs(TreeNode root, int preSum){
        if(root == null){
            return 0;
        }
        preSum = preSum + root.val;
        if(root.left == null && root.right == null){
            return preSum;
        }
        int leftRet = dfs(root.left, preSum * 10);
        int rightRet = dfs(root.right, preSum * 10);
        return leftRet + rightRet;

    }
}
class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}

class Solution {
    public TreeNode invertTree(TreeNode root) {
        if(root == null){
            return null;
        }
        TreeNode tmp = invertTree(root.left);
        root.left = invertTree(root.right);
        root.right = tmp;
        return root;
    }
}

class ListNode {
      int val;
      ListNode next;
      ListNode() {}
     ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next;
      }
class Solution {
    public ListNode swapPairs(ListNode head) {
        return dfs(head);
    }
    public ListNode dfs(ListNode root){
        if(root == null || root.next == null){
            return root;
        }
        //先把两个节点之后的节点交换
        ListNode tmp = dfs(root.next.next);
        ListNode rootNext = root.next;
        root.next = tmp;
        rootNext.next = root;
        return rootNext;
    }
}
public class Test {


}
}
